import time

from Case.python_ui.Common.basepage import Basepage
from Case.python_ui.PageLocate.product_management_locator import ProductManagementLocator
from Case.python_ui.Common.commontool import CommonTool
from Case.python_ui.Test_data.common_data import Commondata
from Case.python_ui.Test_data.prod_data import Product
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import StaleElementReferenceException
from Case.python_ui.mylogging.mylogging import MyLogging
from Case.python_ui.Common.business_common_tool import BusinessCommonTools


class ProductManagementPages(Basepage):


    def  enter_product_category_page(self):
         doc='进入到productmanagement页面'
         for i in range(3):
             try:
                eles=self.get_elements(ProductManagementLocator.default_page_expanded,doc)
                for ele in eles:
                    ele.click()
                    time.sleep(1)
                self.wait_elevisble(ProductManagementLocator.prod_managent_tab,doc)
                self.click_element(ProductManagementLocator.prod_managent_tab,doc)
                self.wait_elevisble(ProductManagementLocator.prod_category_tab,doc)
                self.click_element(ProductManagementLocator.prod_category_tab,doc)
                break
             except:
                 self.refresh_page()
                 continue
         time.sleep(5)


    def  enter_marketplace_category_page(self):
         doc='进入到marketplacecategory页面'
         for i in range(3):
             try:
                eles=self.get_elements(ProductManagementLocator.default_page_expanded,doc)
                for ele in eles:
                    ele.click()
                    time.sleep(1)
                self.wait_elevisble(ProductManagementLocator.prod_managent_tab,doc)
                self.click_element(ProductManagementLocator.prod_managent_tab,doc)
                self.wait_elevisble(ProductManagementLocator.marketplace_category_tab,doc)
                self.click_element(ProductManagementLocator.marketplace_category_tab,doc)
                break
             except:
                 self.refresh_page()
                 continue
         time.sleep(5)



    def enter_my_resource_page(self):
        doc='进入user端的myresource页面'
        for i in range(3):
            try:
                self.wait_elevisble(ProductManagementLocator.my_resource_tab, doc)
                self.click_element(ProductManagementLocator.my_resource_tab, doc)
                break
            except:
                self.refresh_page()
                continue
        time.sleep(5)
        self.wait_elevisble(ProductManagementLocator.check_order_button,doc)
        self.click_element(ProductManagementLocator.check_order_button,doc)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait,doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait,doc)
        except:
            pass
        self.wait_elevisble(ProductManagementLocator.page_total,doc)
        self.wait_elevisble(ProductManagementLocator.check_order_button,doc)
        self.click_element(ProductManagementLocator.check_order_button,doc)
        time.sleep(2)


    def enter_resource_package_page(self):
        doc='进入user端的myresource页面'
        for i in range(3):
            try:
                self.wait_elevisble(ProductManagementLocator.resource_package, doc)
                self.click_element(ProductManagementLocator.resource_package, doc)
                break
            except:
                self.refresh_page()
                continue
        time.sleep(5)
        self.wait_elevisble(ProductManagementLocator.page_total,doc)





    def create_prod_category(self):
        doc='创建产品类别'
        category_name=CommonTool.generate_string()
        MyLogging.get_logging(category_name,'INFO','test',doc)
        self.enter_product_category_page()
        self.click_element(ProductManagementLocator.category_add_button,doc)
        self.wait_elevisble(ProductManagementLocator.category_name,doc)
        self.send_keys(ProductManagementLocator.category_name,category_name,doc)
        time.sleep(2)
        self.send_keys(ProductManagementLocator.category_icon,Commondata.upload_file_path,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.public_confirm_button,doc)
        self.wait_elevisble(ProductManagementLocator.opreation_prompt,doc)
        return category_name


    def query_prod_category(self,category_name):
        doc='查询产品类别'
        self.send_keys(ProductManagementLocator.category_name_input,category_name,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.category_query_button,doc)
        self.wait_elevisble(ProductManagementLocator.category_list,doc)
        time.sleep(2)
        category_list=self.get_elements(ProductManagementLocator.category_list,doc)
        category_list[0].click()
        return category_list




    def delete_prod_category(self,category_name):
        doc = '删除产品类别'
        self.refresh_page()
        self.enter_product_category_page()
        self.query_prod_category(category_name)
        self.move_mouse_to_click_element(ProductManagementLocator.action_list,doc)
        self.wait_elevisble(ProductManagementLocator.operation_type,doc)
        self.get_operation_name_click('Delete')
        self.wait_elevisble(ProductManagementLocator.opreation_prompt,doc)


    def get_operation_name_click(self, operation):
        doc = '通过操作的名称去点击'
        eles = self.get_elements(ProductManagementLocator.operation_type, doc)
        for ele in eles:
            if ele.text == operation:
                time.sleep(2)
                ele.click()



    def edit_prod_category(self,category_name):
        doc='编辑产品类别'
        self.refresh_page()
        self.enter_product_category_page()
        self.query_prod_category(category_name)
        self.move_mouse_to_click_element(ProductManagementLocator.action_list, doc)
        self.wait_elevisble(ProductManagementLocator.operation_type, doc)
        self.get_operation_name_click('Edit')
        edit_category_name=CommonTool.generate_edit_org_name()
        self.wait_elevisble(ProductManagementLocator.category_name,doc)
        self.keyboard_event(ProductManagementLocator.category_name,doc)
        self.send_keys(ProductManagementLocator.category_name,edit_category_name,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.public_confirm_button,doc)
        self.wait_elevisble(ProductManagementLocator.opreation_prompt,doc)
        return edit_category_name


    def create_new_product(self,category_name):
        doc='创建产品'
        self.refresh_page()
        self.enter_product_category_page()
        self.query_prod_category(category_name)
        self.wait_elevisble(ProductManagementLocator.product_create_button,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.product_create_button,doc)
        self.wait_elevisble(ProductManagementLocator.prod_default_name,doc)
        self.click_element(ProductManagementLocator.prod_default_name,doc)
        time.sleep(2)
        eles=self.get_elements(ProductManagementLocator.options,doc)
        eles[0].click()
        time.sleep(2)
        display_name=CommonTool.generate_string()
        self.keyboard_event(ProductManagementLocator.prod_display_name,doc)
        self.send_keys(ProductManagementLocator.prod_display_name,display_name,doc)
        self.send_keys(ProductManagementLocator.prod_special_offer_url_address,Product.test_url,doc)
        self.send_keys(ProductManagementLocator.prod_conditions_offer_url_address,Product.test_url,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.region_id_select,doc)
        time.sleep(2)
        ele=self.get_element(ProductManagementLocator.region_id_select,doc)
        action = ActionChains(self.driver)
        action.move_to_element(ele)
        action.move_by_offset(0, 100)
        time.sleep(1)
        action.click()
        action.perform()
        self.wait_elevisble(ProductManagementLocator.prod_console_url,doc)
        self.send_keys(ProductManagementLocator.prod_console_url,Product.test_url,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.create_prod_button_confirm,doc)
        self.wait_elevisble(ProductManagementLocator.opreation_prompt,doc)
        return display_name

    def delet_product_info(self,category_name):
        doc='删除产品'
        self.refresh_page()
        self.enter_product_category_page()
        self.query_prod_category(category_name)
        self.wait_elevisble(ProductManagementLocator.prod_actions,doc)
        time.sleep(2)
        self.move_mouse_to_click_element(ProductManagementLocator.prod_actions,doc)
        self.get_operation_name_click('Delete')
        self.wait_elevisble(ProductManagementLocator.prod_delete_confirm,doc)
        self.click_element(ProductManagementLocator.prod_delete_confirm,doc)
        self.wait_elevisble(ProductManagementLocator.opreation_prompt,doc)


    def edit_product_info(self,category_name):
        doc='编辑产品'
        self.refresh_page()
        self.enter_product_category_page()
        self.query_prod_category(category_name)
        self.wait_elevisble(ProductManagementLocator.prod_actions, doc)
        time.sleep(2)
        self.move_mouse_to_click_element(ProductManagementLocator.prod_actions, doc)
        time.sleep(2)
        try:
            self.get_operation_name_click('Edit')
        except StaleElementReferenceException:
            self.get_operation_name_click('Edit')
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.create_prod_button_confirm,doc)
        self.click_element(ProductManagementLocator.create_prod_button_confirm,doc)
        self.wait_elevisble(ProductManagementLocator.opreation_prompt,doc)

    def config_tariff_plan(self):
        doc='配置资费计划'
        self.refresh_page()
        self.enter_product_category_page()
        self.query_prod_category(Product.test_category)
        self.wait_elevisble(ProductManagementLocator.prod_name_input,doc)
        self.send_keys(ProductManagementLocator.prod_name_input,Product.test_prod,doc)
        self.click_element(ProductManagementLocator.prod_search_button,doc)
        self.wait_elevisble(ProductManagementLocator.price_plan_btn,doc)
        self.click_element(ProductManagementLocator.price_plan_btn,doc)
        self.wait_elevisble(ProductManagementLocator.loading_wait,doc)
        self.wait_eleinvisble(ProductManagementLocator.loading_wait,doc)
        ele=self.get_element(ProductManagementLocator.price_plan_edit,doc)
        self.driver.execute_script("arguments[0].scrollIntoView(true);", ele)
        self.wait_elevisble(ProductManagementLocator.price_plan_edit,doc)
        self.click_element(ProductManagementLocator.price_plan_edit,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.price_plan_edit,doc)
        self.wait_elevisble(ProductManagementLocator.opreation_prompt,doc)



    def check_product(self):
        doc='检查用户端的数据'
        self.click_element(ProductManagementLocator.mian_menu,doc)
        self.wait_elevisble(ProductManagementLocator.prioduct_list,doc)
        eles=self.get_elements(ProductManagementLocator.prioduct_list,doc)
        time.sleep(2)
        prod_list=[ele.text for ele in eles]
        print(prod_list)
        return prod_list

    def create_marketplace_category(self):
        marketplace_category_name = CommonTool.generate_string()
        doc = '创建市场类别'
        self.enter_marketplace_category_page()
        self.click_element(ProductManagementLocator.category_add_button,doc)
        self.wait_elevisble(ProductManagementLocator.level_menu_name_input,doc)
        self.send_keys(ProductManagementLocator.level_menu_name_input,marketplace_category_name,doc)
        self.click_element(ProductManagementLocator.public_confirm_button,doc)
        return marketplace_category_name



    def query_marketplace_category(self,marketplace_category_name):
        doc='查询市场类别'
        self.keyboard_event(ProductManagementLocator.category_name_input,doc)
        self.send_keys(ProductManagementLocator.category_name_input, marketplace_category_name, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.category_query_button, doc)
        try:
            self.wait_elevisble(ProductManagementLocator.market_category_list, doc)
            time.sleep(2)
            category_list = self.get_elements(ProductManagementLocator.market_category_list, doc)
            category_list[0].click()
            return category_list
        except:
            pass



    def delete_marketplace_category(self,marketplace_category_name):
        doc='删除市场类别'
        self.refresh_page()
        self.enter_marketplace_category_page()
        self.query_marketplace_category(marketplace_category_name)
        time.sleep(2)
        self.move_mouse_to_click_element(ProductManagementLocator.market_category_action, doc)
        self.get_operation_name_click('Delete')
        self.wait_elevisble(ProductManagementLocator.marketplace_confirm_button, doc)
        self.click_element(ProductManagementLocator.marketplace_confirm_button, doc)
        self.wait_elevisble(ProductManagementLocator.opreation_prompt,doc)



    def edit_marketplace_category(self,marketplace_category_name):
        doc='编辑市场类别'
        edit_menu_name=CommonTool.generate_string()
        self.refresh_page()
        self.enter_marketplace_category_page()
        self.query_marketplace_category(marketplace_category_name)
        time.sleep(2)
        self.move_mouse_to_click_element(ProductManagementLocator.market_category_action, doc)
        self.get_operation_name_click('Edit')
        self.wait_elevisble(ProductManagementLocator.menu_name_input,doc)
        self.keyboard_event(ProductManagementLocator.menu_name_input,doc)
        self.send_keys(ProductManagementLocator.menu_name_input,edit_menu_name,doc)
        self.click_element(ProductManagementLocator.public_confirm_button,doc)
        self.wait_elevisble(ProductManagementLocator.opreation_prompt, doc)
        return edit_menu_name



    def  order_nas(self):
        doc='订购nas'
        self.enter_my_resource_page()
        self.get_resouce_name_to_click('Storage')
        self.wait_elevisble(ProductManagementLocator.cerate_new_tab,doc)
        self.move_mouse_to_element(ProductManagementLocator.cerate_new_tab)
        time.sleep(2)
        self.get_prod_name_to_click('NAS File System')
        time.sleep(2)
        try:
            self.switch_to_new_window()
            self.wait_elevisble(ProductManagementLocator.term_of_service,doc)
            time.sleep(2)
            self.click_element(ProductManagementLocator.term_of_service,doc)
            time.sleep(2)
            self.button_is_enabled(ProductManagementLocator.buy_now_button)
            self.wait_elevisble(ProductManagementLocator.pay_button,doc)
            time.sleep(2)
            self.click_element(ProductManagementLocator.pay_button, doc)
            self.wait_elevisble(ProductManagementLocator.pay_successful,doc)
        except:
            self.driver.close()
            all_handles = self.driver.window_handles
            self.driver.switch_to.window(all_handles[0])


    def nas_configuration_change(self):
        doc = '变配nas'
        self.enter_resource_package_page()
        self.wait_elevisble(ProductManagementLocator.resource_modify_button,doc)
        self.click_element(ProductManagementLocator.resource_modify_button,doc)
        time.sleep(2)
        try:
            self.switch_to_new_window()
            self.wait_elevisble(ProductManagementLocator.term_of_service, doc)
            time.sleep(2)
            self.click_element(ProductManagementLocator.term_of_service, doc)
            time.sleep(2)
            self.button_is_enabled(ProductManagementLocator.buy_now_button)
            self.wait_elevisble(ProductManagementLocator.pay_button, doc)
            time.sleep(2)
            self.click_element(ProductManagementLocator.pay_button, doc)
            time.sleep(5)
            self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
        except:
            self.driver.close()
            all_handles = self.driver.window_handles
            self.driver.switch_to.window(all_handles[0])

    def renew_nas(self):
        doc = '续订NAS'
        self.enter_resource_package_page()
        self.wait_elevisble(ProductManagementLocator.resource_renew_button, doc)
        self.click_element(ProductManagementLocator.resource_renew_button,doc)
        time.sleep(2)
        try:
            self.switch_to_new_window()
            self.wait_elevisble(ProductManagementLocator.term_of_service, doc)
            time.sleep(2)
            self.click_element(ProductManagementLocator.term_of_service, doc)
            time.sleep(2)
            self.button_is_enabled(ProductManagementLocator.buy_now_button)
            self.wait_elevisble(ProductManagementLocator.pay_button, doc)
            time.sleep(2)
            self.click_element(ProductManagementLocator.pay_button, doc)
            time.sleep(5)
            self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
        except:
            self.driver.close()
            all_handles = self.driver.window_handles
            self.driver.switch_to.window(all_handles[0])



    def get_resouce_name_to_click(self,resource_name):
        doc='获取到资源名称然后点击'
        resource_list = self.get_elements(ProductManagementLocator.resources, doc)
        for resource in  resource_list:
            if resource.text==resource_name:
                resource.click()
        time.sleep(2)


    def get_prod_name_to_click(self,prod_name):
        doc='获取产品名称然后点击'
        prod_list=self.get_elements(ProductManagementLocator.prod_list,doc)
        time.sleep(2)
        for prod in prod_list:
            if prod.text == prod_name:
                prod.click()
        time.sleep(2)



    def nas_console(self):
        doc='nas控制台'
        self.click_element(ProductManagementLocator.menu_list,doc)
        self.wait_elevisble(ProductManagementLocator.resources_list,doc)
        time.sleep(2)
        eles=self.get_elements(ProductManagementLocator.resources_list,doc)
        resources_list=[ele.text for ele in eles]
        return resources_list

    def order_private_cloud_as_you_go_disks(self,cmdopt):
        doc='订购私有云按量付费磁盘'
        self.enter_my_resource_page()
        self.get_resouce_name_to_click('Storage')
        self.wait_elevisble(ProductManagementLocator.cerate_new_tab, doc)
        self.move_mouse_to_element(ProductManagementLocator.cerate_new_tab)
        time.sleep(2)
        self.get_prod_name_to_click('Block Storage')
        time.sleep(2)
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait,doc)
        except:
            pass
        self.wait_elevisble(ProductManagementLocator.pay_as_you_go_button,doc)
        time.sleep(5)
        self.click_element(ProductManagementLocator.pay_as_you_go_button,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.term_of_service,doc)
        time.sleep(1)
        self.button_is_enabled(ProductManagementLocator.buy_now_button)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.view_detail,doc)
        self.move_mouse_to_element(ProductManagementLocator.view_detail)
        time.sleep(2)
        deatil=self.get_product_detail()
        time.sleep(1)
        self.click_element(ProductManagementLocator.pay_button,doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful,doc)
        self.click_element(ProductManagementLocator.check_order_button,doc)
        self.wait_elevisble(ProductManagementLocator.order_view_detail_button,doc)
        eles=self.get_elements(ProductManagementLocator.order_view_detail_button,doc)
        eles[0].click()
        self.wait_elevisble(ProductManagementLocator.order_details,doc)
        order_detail=self.get_order_details()
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        disk_instance_id=self.get_disk_instance_id(cmdopt)
        print(disk_instance_id)
        return  deatil ,order_detail,disk_instance_id

    def get_product_detail(self):
        doc='获取产品的detail'
        eles=self.get_elements(ProductManagementLocator.detail_element,doc)
        detail_list=[ele.text for ele in eles]
        print(detail_list)
        return detail_list


    def get_order_details(self):
        doc='获取订单中的details'
        eles=self.get_elements(ProductManagementLocator.order_details,doc)
        order_detail_list=[ele.text for ele in eles]
        del order_detail_list[-1]
        del order_detail_list[-1]
        print(order_detail_list)
        new_list = []
        for i in order_detail_list:
            new_list.append(i.split(': ')[1])
        print(new_list)
        return new_list

    def modify_private_cloud_as_you_go_disks(self,disk_instance_id):
        doc='变配私有云按量付费磁盘'
        self.refresh_page()
        self.enter_my_resource_page()
        time.sleep(2)
        self.query_intance_id(disk_instance_id)
        self.wait_elevisble(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.move_mouse_to_click_element(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.get_action_to_click('Modify')
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait,doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait,doc)
        except:
            pass
        time.sleep(2)
        self.keyboard_event(ProductManagementLocator.capaity_input,doc)
        capactiy=CommonTool.generate_less_than_certain_value(100)
        self.send_keys(ProductManagementLocator.capaity_input,capactiy,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.term_of_service,doc)
        time.sleep(2)
        self.button_is_enabled(ProductManagementLocator.buy_now_button)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait,doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait,doc)
        except:
            pass
        time.sleep(2)
        self.click_element(ProductManagementLocator.pay_button,doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful,doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])


    def get_action_to_click(self,action_name):
        doc='获取操作名称然后点击'
        self.wait_elevisble(ProductManagementLocator.my_resource_action_list,doc)
        action_list_eles =self.get_elements(ProductManagementLocator.my_resource_action_list,doc)
        for action in action_list_eles:
            if action.text== action_name:
                action.click()


    def release_private_cloud_as_you_go_disks(self,disk_instance_id):
        doc = '释放按量付费磁盘'
        self.refresh_page()
        self.enter_my_resource_page()
        self.query_intance_id(disk_instance_id)
        self.wait_elevisble(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.move_mouse_to_click_element(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.get_action_to_click('Release')
        time.sleep(2)
        self.switch_to_new_window()
        self.wait_elevisble(ProductManagementLocator.release_button,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.release_button,doc)
        self.wait_elevisble(ProductManagementLocator.buy_now_button,doc)
        self.click_element(ProductManagementLocator.buy_now_button,doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful,doc)


    def subscribe_to_the_annual_subscription_disk_of_private_cloud_package(self,cmdopt):
        doc='订购私有云包年包月磁盘'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.get_resouce_name_to_click('Storage')
        self.wait_elevisble(ProductManagementLocator.cerate_new_tab, doc)
        self.move_mouse_to_element(ProductManagementLocator.cerate_new_tab)
        time.sleep(2)
        self.get_prod_name_to_click('Block Storage')
        time.sleep(2)
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        time.sleep(5)
        self.click_element(ProductManagementLocator.ecs_select,doc)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.ecs_option,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.ecs_option,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.term_of_service,doc)
        self.button_is_enabled(ProductManagementLocator.buy_now_button)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait,doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait,doc)
        except:
            pass
        self.wait_elevisble(ProductManagementLocator.pay_button,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.pay_button,doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful,doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        disk_instance_id=self.get_disk_instance_id(cmdopt)
        print(disk_instance_id)
        return disk_instance_id


    def get_disk_instance_id(self,cmdopt):
        doc='获取disk_instance_di'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.get_resouce_name_to_click('Storage')
        self.wait_elevisble(ProductManagementLocator.reset_button,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.reset_button,doc)
        self.wait_elevisble(ProductManagementLocator.loading_wait,doc)
        self.wait_eleinvisble(ProductManagementLocator.loading_wait,doc)
        disk_instance_id=self.get_element(ProductManagementLocator.disk_instance_id,doc).text
        return  disk_instance_id



    def renew_to_the_annual_subscription_disk_of_private_cloud_package(self,disk_instance_id):
        doc = '续订私有云包年包月磁盘'
        self.refresh_page()
        self.enter_my_resource_page()
        #self.get_resouce_name_to_click('Storage')
        #self.click_element(ProductManagementLocator.reset_button,doc)
        #self.wait_elevisble(ProductManagementLocator.loading_wait,doc)
        #self.wait_eleinvisble(ProductManagementLocator.loading_wait,doc)
        #self.wait_elevisble(ProductManagementLocator.renew_button, doc)
        time.sleep(2)
        self.query_intance_id(disk_instance_id)
        self.wait_elevisble(ProductManagementLocator.renew_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.renew_button, doc)
        time.sleep(2)
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait,doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait,doc)
        except:
            pass
        self.click_element(ProductManagementLocator.term_of_service,doc)
        self.button_is_enabled(ProductManagementLocator.buy_now_button)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait,doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait,doc)
        except:
            pass
        self.click_element(ProductManagementLocator.pay_button,doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful,doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])

    def modify_to_the_annual_subscription_disk_of_private_cloud_package(self,disk_instance_id):
            doc = '变配私有云包年包月磁盘'
            self.refresh_page()
            self.enter_my_resource_page()
            time.sleep(2)
            self.query_intance_id(disk_instance_id)
            self.wait_elevisble(ProductManagementLocator.action_button, doc)
            self.click_element(ProductManagementLocator.action_button, doc)
            time.sleep(2)
            self.get_action_to_click('Modify')
            self.switch_to_new_window()
            try:
                self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
                self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
            except:
                pass
            time.sleep(2)
            self.keyboard_event(ProductManagementLocator.capaity_input, doc)
            capactiy = CommonTool.generate_less_than_certain_value(100)
            self.send_keys(ProductManagementLocator.capaity_input, capactiy, doc)
            time.sleep(2)
            self.click_element(ProductManagementLocator.term_of_service, doc)
            self.button_is_enabled(ProductManagementLocator.buy_now_button)
            try:
                self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
                self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
            except:
                pass
            time.sleep(2)
            self.click_element(ProductManagementLocator.pay_button, doc)
            self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
            self.driver.close()
            all_handles = self.driver.window_handles
            self.driver.switch_to.window(all_handles[0])





    def create_subscription_esc(self,cmdopt):
        doc='创建一个esc'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.wait_elevisble(ProductManagementLocator.cerate_new_tab, doc)
        self.move_mouse_to_element(ProductManagementLocator.cerate_new_tab)
        time.sleep(2)
        self.get_prod_name_to_click('Elastic Compute Service')
        time.sleep(2)
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait,doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait,doc)
        except:
            pass
        time.sleep(2)
        self.get_category_to_click('General Purpose High Performance')
        intance_name=CommonTool.generate_string()
        self.wait_elevisble(ProductManagementLocator.instance_name_input,doc)
        time.sleep(2)
        self.send_keys(ProductManagementLocator.instance_name_input,intance_name,doc)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        self.click_element(ProductManagementLocator.cpu_select,doc)
        self.wait_elevisble(ProductManagementLocator.cpu_option,doc)
        eles=self.get_elements(ProductManagementLocator.cpu_option,doc)
        eles[0].click()
        time.sleep(2)
        self.click_element(ProductManagementLocator.image_1_select,doc)
        self.wait_elevisble(ProductManagementLocator.image_1_options,doc)
        image_eles=self.get_elements(ProductManagementLocator.image_1_options,doc)
        image_eles[0].click()
        time.sleep(2)
        self.click_element(ProductManagementLocator.deployment_set_select,doc)
        self.wait_elevisble(ProductManagementLocator.deployment_set_option,doc)
        deployment_set=self.get_elements(ProductManagementLocator.deployment_set_option,doc)
        deployment_set[0].click()
        time.sleep(2)
        self.click_element(ProductManagementLocator.vpc_select,doc)
        self.wait_elevisble(ProductManagementLocator.vpc_option,doc)
        vpc_switch_eles=self.get_elements(ProductManagementLocator.vpc_option,doc)
        vpc_switch_eles[0].click()
        time.sleep(2)
        self.click_element(ProductManagementLocator.switch_select, doc)
        self.wait_elevisble(ProductManagementLocator.switch_option, doc)
        switch_eles = self.get_elements(ProductManagementLocator.switch_option, doc)
        switch_eles[0].click()
        time.sleep(2)
        self.click_element(ProductManagementLocator.security_group_select, doc)
        self.wait_elevisble(ProductManagementLocator.security_group_option, doc)
        switch_eles = self.get_elements(ProductManagementLocator.security_group_option, doc)
        switch_eles[0].click()
        self.send_keys(ProductManagementLocator.login_password_input,'asdQWE123~!@',doc)
        self.send_keys(ProductManagementLocator.confirm_password_input,'asdQWE123~!@',doc)
        self.click_element(ProductManagementLocator.term_of_service,doc)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        self.button_is_enabled(ProductManagementLocator.buy_now_button)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait,doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait,doc)
        except:
            pass
        self.wait_elevisble(ProductManagementLocator.pay_button,doc)
        time.sleep(5)
        self.click_element(ProductManagementLocator.pay_button,doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful,doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        return intance_name

    def  order_oss_trafficplan(self):
        doc='订购Outbound Traffic Plan的OSS'
        self.enter_my_resource_page()
        self.get_resouce_name_to_click('Storage')
        self.wait_elevisble(ProductManagementLocator.cerate_new_tab, doc)
        self.move_mouse_to_element(ProductManagementLocator.cerate_new_tab)
        time.sleep(2)
        self.get_prod_name_to_click('Object Storage Service')
        time.sleep(2)
        self.switch_to_new_window()
        self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        time.sleep(5)
        self.click_element(ProductManagementLocator.term_of_service, doc)
        time.sleep(1)
        self.button_is_enabled(ProductManagementLocator.buy_now_button)
        self.wait_elevisble(ProductManagementLocator.view_detail, doc)
        self.move_mouse_to_element(ProductManagementLocator.view_detail)
        time.sleep(2)
        detail = self.get_product_detail()
        time.sleep(1)
        self.click_element(ProductManagementLocator.pay_button, doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
        self.click_element(ProductManagementLocator.check_order_button, doc)
        self.wait_elevisble(ProductManagementLocator.order_view_detail_button, doc)
        eles = self.get_elements(ProductManagementLocator.order_view_detail_button, doc)
        eles[0].click()
        self.wait_elevisble(ProductManagementLocator.order_details, doc)
        order_detail = self.get_order_details()
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        return detail, order_detail

    def create_ecs_pay_as_you_go(self,cmdopt):
        doc='创建一个esc pay_as_you_go'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.wait_elevisble(ProductManagementLocator.cerate_new_tab, doc)
        self.move_mouse_to_element(ProductManagementLocator.cerate_new_tab)
        time.sleep(2)
        self.get_prod_name_to_click('Elastic Compute Service')
        time.sleep(2)
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait,doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait,doc)
        except:
            pass
        self.wait_elevisble(ProductManagementLocator.pay_as_you_go_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.pay_as_you_go_button,doc)
        self.get_category_to_click('General Purpose Standard Performance')
        intance_name=CommonTool.generate_string()
        self.wait_elevisble(ProductManagementLocator.instance_name_input, doc)
        self.send_keys(ProductManagementLocator.instance_name_input, intance_name, doc)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait,doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait,doc)
        except:
            pass
        self.click_element(ProductManagementLocator.cpu_select, doc)
        self.wait_elevisble(ProductManagementLocator.cpu_option, doc)
        eles = self.get_elements(ProductManagementLocator.cpu_option, doc)
        eles[0].click()
        time.sleep(2)
        self.click_element(ProductManagementLocator.image_1_select, doc)
        self.wait_elevisble(ProductManagementLocator.image_1_options, doc)
        image_eles = self.get_elements(ProductManagementLocator.image_1_options, doc)
        image_eles[0].click()
        time.sleep(2)
        self.click_element(ProductManagementLocator.deployment_set_select, doc)
        self.wait_elevisble(ProductManagementLocator.deployment_set_option, doc)
        deployment_set = self.get_elements(ProductManagementLocator.deployment_set_option, doc)
        deployment_set[0].click()
        time.sleep(2)
        self.click_element(ProductManagementLocator.vpc_select, doc)
        self.wait_elevisble(ProductManagementLocator.vpc_option, doc)
        vpc_switch_eles = self.get_elements(ProductManagementLocator.vpc_option, doc)
        vpc_switch_eles[0].click()
        time.sleep(2)
        self.click_element(ProductManagementLocator.switch_select, doc)
        self.wait_elevisble(ProductManagementLocator.switch_option, doc)
        switch_eles = self.get_elements(ProductManagementLocator.switch_option, doc)
        switch_eles[0].click()
        time.sleep(2)
        self.click_element(ProductManagementLocator.security_group_select, doc)
        self.wait_elevisble(ProductManagementLocator.security_group_option, doc)
        switch_eles = self.get_elements(ProductManagementLocator.security_group_option, doc)
        switch_eles[0].click()
        self.send_keys(ProductManagementLocator.login_password_input, 'asdQWE123~!@', doc)
        self.send_keys(ProductManagementLocator.confirm_password_input, 'asdQWE123~!@', doc)
        self.click_element(ProductManagementLocator.term_of_service, doc)
        self.button_is_enabled(ProductManagementLocator.buy_now_button)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.pay_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.pay_button, doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        return  intance_name


    def stop_and_delete_ecs(self):
        doc='关机和删除创建的ecs'
        self.refresh_page()
        self.wait_elevisble(ProductManagementLocator.menu_list,doc)
        self.click_element(ProductManagementLocator.menu_list,doc)
        self.wait_elevisble(ProductManagementLocator.resources_list,doc)
        self.click_element(ProductManagementLocator.resources_list,doc)
        self.wait_elevisble(ProductManagementLocator.loading_wait,doc)
        self.wait_eleinvisble(ProductManagementLocator.loading_wait,doc)
        self.wait_elevisble(ProductManagementLocator.iframe,doc)
        self.driver.switch_to.frame(self.get_element(ProductManagementLocator.iframe,doc))
        self.wait_elevisble(ProductManagementLocator.status,doc)

    def wait_status_to_running(self,intance_name):
        doc='等待状态变成running'
        self.refresh_page()
        self.wait_elevisble(ProductManagementLocator.menu_list, doc)
        self.click_element(ProductManagementLocator.menu_list, doc)
        self.get_console_product_to_click('Elastic Compute Service')
        time.sleep(4)
        self.wait_elevisble(ProductManagementLocator.iframe, doc)
        self.driver.switch_to.frame(self.get_element(ProductManagementLocator.iframe, doc))
        self.wait_elevisble(ProductManagementLocator.status, doc)
        self.query_instance(intance_name)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.instance_id_ele,doc)
        intance_id=self.get_element(ProductManagementLocator.instance_id_ele,doc).text
        print(intance_id)
        while True:
            time.sleep(5)
            status=self.get_element(ProductManagementLocator.status, doc).text
            if status == 'Running':
                break
            else:
                self.click_element(ProductManagementLocator.refresh_button,doc)
        return  intance_id


    def stop_ecs_and_wait_status_to_stopped(self,intance_name):
        doc='关机并且等待状态变为stopped'
        self.driver.refresh()
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.menu_list, doc)
        self.click_element(ProductManagementLocator.menu_list, doc)
        self.get_console_product_to_click('Elastic Compute Service')
        time.sleep(4)
        self.wait_elevisble(ProductManagementLocator.iframe, doc)
        self.driver.switch_to.frame(self.get_element(ProductManagementLocator.iframe, doc))
        self.wait_elevisble(ProductManagementLocator.status, doc)
        self.query_instance(intance_name)
        self.move_mouse_to_click_element(ProductManagementLocator.intance_status,doc)
        self.wait_elevisble(ProductManagementLocator.stop_instance,doc)
        self.click_element(ProductManagementLocator.stop_instance,doc)
        self.wait_elevisble(ProductManagementLocator.stop_instance_confirm,doc)
        self.click_element(ProductManagementLocator.stop_instance_confirm,doc)
        time.sleep(2)
        while True:
            time.sleep(5)
            status = self.get_element(ProductManagementLocator.status, doc).text
            if status == 'Stopped':
                break
            else:
                self.click_element(ProductManagementLocator.refresh_button, doc)


    def release_subscripition_ecs(self,cmdopt,instance_id):
        doc = '释放subscripition_ecs'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.query_intance_id(instance_id)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.get_action_to_click('Release')
        self.switch_to_new_window()
        self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
        self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.release_button,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.release_button,doc)
        self.wait_elevisble(ProductManagementLocator.buy_now_button,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.buy_now_button,doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful,doc)

    def release_disk(self, cmdopt, disk_instance_id):
        doc = '释放subscripition_ecs'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.query_intance_id(disk_instance_id)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.get_action_to_click('Release')
        self.switch_to_new_window()
        self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
        self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        self.wait_elevisble(ProductManagementLocator.release_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.release_button, doc)
        self.wait_elevisble(ProductManagementLocator.buy_now_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.buy_now_button, doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful, doc)



    def delete_ecs(self,intance_name):
        doc='删除ecs'
        self.driver.refresh()
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.menu_list, doc)
        self.click_element(ProductManagementLocator.menu_list, doc)
        self.wait_elevisble(ProductManagementLocator.resources_list, doc)
        self.click_element(ProductManagementLocator.resources_list, doc)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        self.wait_elevisble(ProductManagementLocator.iframe, doc)
        self.driver.switch_to.frame(self.get_element(ProductManagementLocator.iframe, doc))
        self.wait_elevisble(ProductManagementLocator.status, doc)
        self.query_instance(intance_name)
        self.move_mouse_to_click_element(ProductManagementLocator.intance_status, doc)
        self.wait_elevisble(ProductManagementLocator.delete_instance, doc)
        self.click_element(ProductManagementLocator.delete_instance, doc)
        self.wait_elevisble(ProductManagementLocator.stop_instance_confirm, doc)
        self.click_element(ProductManagementLocator.stop_instance_confirm, doc)
        time.sleep(5)

    def renew_subscripition_ecs(self,cmdopt,instance_id):
        doc='续费ecs'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.query_intance_id(instance_id)
        self.wait_elevisble(ProductManagementLocator.order_view_detail_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.order_view_detail_button, doc)
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        self.wait_elevisble(ProductManagementLocator.term_of_service, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.term_of_service, doc)
        self.button_is_enabled(ProductManagementLocator.buy_now_button)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        self.wait_elevisble(ProductManagementLocator.pay_button, doc)
        self.click_element(ProductManagementLocator.pay_button, doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])


    def modify_subscripition_ecs(self,cmdopt,instance_id):
        doc='变配ecs'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.query_intance_id(instance_id)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.get_action_to_click('Modify')
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.instance_family,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.instance_family,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.term_of_service,doc)
        self.button_is_enabled(ProductManagementLocator.buy_now_button)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        time.sleep(2)
        self.click_element(ProductManagementLocator.pay_button,doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful,doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])


    def charge_transfer_sub_psgy(self,cmdopt,instance_id):
        doc='计费互转'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.query_intance_id(instance_id)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.billing_method_change,doc)
        self.click_element(ProductManagementLocator.billing_method_change,doc)
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait,doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait,doc)
        except:
            pass
        self.wait_elevisble(ProductManagementLocator.term_of_service,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.term_of_service,doc)
        time.sleep(2)
        self.button_is_enabled(ProductManagementLocator.billing_method_change_buy_now)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait,doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait,doc)
        except:
            pass
        self.wait_elevisble(ProductManagementLocator.pay_button,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.pay_button,doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful,doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])

    def enterprise_user_instance_change_organization(self,cmdopt,instance_id,org_name):
        doc = '企业用户实例更改组织'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.query_intance_id(instance_id)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.get_action_to_click('Change Organization')
        self.wait_elevisble(ProductManagementLocator.change_org_to_input,doc)
        time.sleep(2)
        self.send_keys(ProductManagementLocator.change_org_to_input,org_name,doc)
        self.wait_elevisble(ProductManagementLocator().choose_org_name(org_name),doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator().choose_org_name(org_name),doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.change_org_submit_button,doc)
        self.wait_elevisble(ProductManagementLocator.success_prompt,doc)


    def change_the_operating_system(self,cmdopt,instance_id):
        doc = '更改操作系统'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.query_intance_id(instance_id)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.get_action_to_click('Change Operating System')
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        self.wait_elevisble(ProductManagementLocator.image_3_select,doc)
        time.sleep(4)
        self.click_element(ProductManagementLocator.image_3_select,doc)
        self.wait_elevisble(ProductManagementLocator.region_options,doc)
        eles=self.get_elements(ProductManagementLocator.region_options,doc)
        time.sleep(2)
        eles[1].click()
        time.sleep(2)
        self.click_element(ProductManagementLocator.term_of_service,doc)
        time.sleep(2)
        self.button_is_enabled(ProductManagementLocator.buy_now_button)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait,doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait,doc)
        except:
            pass
        self.wait_elevisble(ProductManagementLocator.gross_amount_ele,doc)
        gross_amount=self.get_element(ProductManagementLocator.gross_amount_ele,doc).text
        tital_to_pay=self.get_element(ProductManagementLocator.total_to_pay_ele,doc).text
        self.wait_elevisble(ProductManagementLocator.pay_button,doc)
        self.click_element(ProductManagementLocator.pay_button,doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        return gross_amount ,tital_to_pay



    def buy_free_ecs(self,cmdopt):
        doc = '购买免费的ecs'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.wait_elevisble(ProductManagementLocator.free_trial,doc)
        self.move_mouse_to_click_element(ProductManagementLocator.free_trial,doc)
        self.get_action_to_click('Elastic Compute Service')
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait,doc)
        except:
            pass
        time.sleep(2)
        intance_name = CommonTool.generate_string()
        self.wait_elevisble(ProductManagementLocator.instance_name_input, doc)
        self.send_keys(ProductManagementLocator.instance_name_input, intance_name, doc)
        time.sleep(5)
        self.click_element(ProductManagementLocator.image_2_select, doc)
        self.wait_elevisble(ProductManagementLocator.image_2_options, doc)
        image_eles = self.get_elements(ProductManagementLocator.image_2_options, doc)
        image_eles[0].click()
        time.sleep(2)
        self.click_element(ProductManagementLocator.deployment_set2_select, doc)
        self.wait_elevisble(ProductManagementLocator.deployment_set2_option, doc)
        deployment_set = self.get_elements(ProductManagementLocator.deployment_set2_option, doc)
        deployment_set[0].click()
        time.sleep(2)
        self.click_element(ProductManagementLocator.vpc2_select, doc)
        self.wait_elevisble(ProductManagementLocator.vpc2_option, doc)
        vpc_switch_eles = self.get_elements(ProductManagementLocator.vpc2_option, doc)
        vpc_switch_eles[0].click()
        time.sleep(2)
        self.click_element(ProductManagementLocator.switch2_select, doc)
        self.wait_elevisble(ProductManagementLocator.switch2_option, doc)
        switch_eles = self.get_elements(ProductManagementLocator.switch2_option, doc)
        switch_eles[0].click()
        time.sleep(2)
        self.click_element(ProductManagementLocator.security_group2_select, doc)
        self.wait_elevisble(ProductManagementLocator.security_group2_option, doc)
        switch_eles = self.get_elements(ProductManagementLocator.security_group2_option, doc)
        switch_eles[0].click()
        self.send_keys(ProductManagementLocator.login_password_input, 'asdQWE123~!@', doc)
        self.send_keys(ProductManagementLocator.confirm_password_input, 'asdQWE123~!@', doc)
        self.click_element(ProductManagementLocator.term_of_service, doc)
        self.button_is_enabled(ProductManagementLocator.buy_now_button)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.pay_button, doc)
        self.click_element(ProductManagementLocator.pay_button, doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        return intance_name


    def check_change_ecs_system_entrance(self,cmdopt,instance_id):
        doc = '检查change_operation_system入口'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.query_intance_id(instance_id)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.my_resource_action_list, doc)
        action_list_eles = self.get_elements(ProductManagementLocator.my_resource_action_list, doc)
        action_list=[action_list_ele.text for  action_list_ele in action_list_eles]
        return action_list

    def ecs_system_entrance_stopped(self,cmdopt,instance_id):
        doc = 'Stopped状态的ECS，进入更改操作系统界面'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.query_intance_id(instance_id)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.get_action_to_click('Change Operating System')
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        operation_tittle=self.get_element(ProductManagementLocator.change_the_operating_system,doc).text
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        return  operation_tittle


    def ecs_system_entrance_running(self,cmdopt,instance_id):
        doc = 'Stopped状态的ECS，进入更改操作系统界面'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.query_intance_id(instance_id)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.get_action_to_click('Change Operating System')
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        operation_tittle=self.get_element(ProductManagementLocator.pay_successful,doc).text
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        return  operation_tittle


    def ecs_with_disk(self,cmdopt,instance_id):
        doc = '带有数据盘的ECS，进入更改操作系统界面'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.query_intance_id(instance_id)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.get_action_to_click('Change Operating System')
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        operation_tittle = self.get_element(ProductManagementLocator.change_the_operating_system, doc).text
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        return operation_tittle


    def ecs_without_disk(self,cmdopt,instance_id):
        doc = '不带有数据盘的ECS，进入更改操作系统界面'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.query_intance_id(instance_id)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.get_action_to_click('Change Operating System')
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        operation_tittle = self.get_element(ProductManagementLocator.pay_successful, doc).text
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        return operation_tittle

    def upgrade_configuration(self, cmdopt, instance_id):
        doc = '升级配置'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.query_intance_id(instance_id)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.get_action_to_click('Modify')
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        self.get_category_to_click('General Purpose High Performance')
        self.wait_elevisble(ProductManagementLocator.instance_familys,doc)
        time.sleep(3)
        eles=self.get_elements(ProductManagementLocator.instance_familys,doc)
        eles[1].click()
        self.click_element(ProductManagementLocator.term_of_service, doc)
        time.sleep(2)
        self.button_is_enabled(ProductManagementLocator.buy_now_button)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.pay_button, doc)
        self.click_element(ProductManagementLocator.pay_button, doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])

    def reduce_configuration(self, cmdopt, instance_id):
        doc = '升级配置'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.query_intance_id(instance_id)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.get_action_to_click('Modify')
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        self.get_category_to_click('General Purpose Standard Performance')
        time.sleep(2)
        self.click_element(ProductManagementLocator.term_of_service, doc)
        time.sleep(2)
        self.button_is_enabled(ProductManagementLocator.buy_now_button)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.pay_button, doc)
        self.click_element(ProductManagementLocator.pay_button, doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])


    def check_public_image_disk(self,cmdopt):
        doc='检查public_image下面的disk'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.wait_elevisble(ProductManagementLocator.cerate_new_tab, doc)
        self.move_mouse_to_element(ProductManagementLocator.cerate_new_tab)
        time.sleep(2)
        self.get_prod_name_to_click('Elastic Compute Service')
        time.sleep(2)
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        self.get_category_to_click('General Purpose Standard Performance')
        time.sleep(2)
        self.click_element(ProductManagementLocator.image_1_select, doc)
        self.wait_elevisble(ProductManagementLocator.image_1_options, doc)
        image_eles = self.get_elements(ProductManagementLocator.image_1_options, doc)
        image_eles[0].click()
        self.wait_elevisble(ProductManagementLocator.total_disk,doc)
        total_disk=self.get_element(ProductManagementLocator.total_disk,doc).text
        print(total_disk)
        time.sleep(2)
        self.click_element(ProductManagementLocator.check_order_button,doc)
        left_disk=self.get_element(ProductManagementLocator.total_disk,doc).text
        print(left_disk)
        return total_disk,left_disk

    def check_custom_image_disk(self, cmdopt):
        doc = '检查custom_image下面的disk'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.wait_elevisble(ProductManagementLocator.cerate_new_tab, doc)
        self.move_mouse_to_element(ProductManagementLocator.cerate_new_tab)
        time.sleep(2)
        self.get_prod_name_to_click('Elastic Compute Service')
        time.sleep(2)
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        self.get_category_to_click('General Purpose Standard Performance')
        time.sleep(2)
        self.click_element(ProductManagementLocator.cpu_select, doc)
        self.wait_elevisble(ProductManagementLocator.cpu_option, doc)
        eles = self.get_elements(ProductManagementLocator.cpu_option, doc)
        eles[0].click()
        time.sleep(2)
        self.click_element(ProductManagementLocator.custom_image_type,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.image_1_select, doc)
        self.wait_elevisble(ProductManagementLocator.image_1_options, doc)
        image_eles = self.get_elements(ProductManagementLocator.image_1_options, doc)
        image_eles[0].click()
        left_disk = self.get_element(ProductManagementLocator.total_disk, doc).text
        print(left_disk)
        input=self.get_element(ProductManagementLocator.delete_disk,doc)
        is_input=input.is_enabled()
        value=input.get_attribute('value')
        return left_disk ,is_input,value

    def query_instance(self,intance_name):
        doc='查询intance_name'
        self.wait_elevisble(ProductManagementLocator.console_instance_name_input,doc)
        self.keyboard_event(ProductManagementLocator.console_instance_name_input,doc)
        self.send_keys(ProductManagementLocator.console_instance_name_input,intance_name,doc)
        self.click_element(ProductManagementLocator.console_search_button,doc)
        self.wait_elevisble(ProductManagementLocator.intance_status,doc)


    def query_intance_id(self,instance_id):
        doc='查询intance_id'
        self.wait_elevisble(ProductManagementLocator.instance_id_input,doc)
        self.keyboard_event(ProductManagementLocator.instance_id_input,instance_id)
        self.send_keys(ProductManagementLocator.instance_id_input,instance_id,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.instance_id_search,doc)
        self.wait_elevisble(ProductManagementLocator.order_view_detail_button,doc)




    def get_resource_to_click(self,resource_name):
        doc='获取资源然后去点击'
        self.wait_elevisble(ProductManagementLocator.resources_list,doc)
        eles=self.get_elements(ProductManagementLocator.resources_list,doc)
        for ele in eles:
            if  ele.text == resource_name:
                ele.click()


    def button_is_enabled(self,locate):
        doc='判断按钮是否可以点击'
        button=self.get_element(locate,doc)
        for i in range(5):
            time.sleep(2)
            if  button.is_enabled():
                button.click()
                break


    def get_console_product_to_click(self,prouduct_name):
        doc = '查询产品名称然后点击'
        self.wait_elevisble(ProductManagementLocator.product_name_input,doc)
        self.send_keys(ProductManagementLocator.product_name_input,prouduct_name,doc)
        self.wait_elevisble(ProductManagementLocator.search_prod_ele,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.search_prod_ele,doc)
        time.sleep(2)


    def get_category_to_click(self,category):
        doc='获取分类配置然后点击'
        self.wait_elevisble(ProductManagementLocator.instance_category, doc)
        eles=self.get_elements(ProductManagementLocator.instance_category, doc)
        for ele in eles:
            if ele.text==category:
                ele.click()
        time.sleep(2)